<template>
  <div>
    <img :src="captchaUrl" alt="captcha" @click="refreshCaptcha">
    <input type="text" v-model="captchaInput">
    <button @click="checkCaptcha">验证</button>
  </div>
</template>
<script>
import axios from 'axios';

export default {
  data() {
    return {
      //captchaUrl: 'http://127.0.0.1:9001/admin/Verify/getCode?' + new Date().getTime(),
      captchaUrl:"",
      captchaInput: '',
      codeUrl: '',
    };
  },
  created() {
    //this.getCode();
    //this.uuid();
  },
  methods: {
    refreshCaptcha() {
      this.getCode();
      // 更新 captchaUrl 以包含新的时间戳，从而强制浏览器重新加载图片
      //this.captchaUrl = 'http://127.0.0.1:9001/admin/Verify/index?' + new Date().getTime();
    },
    /* getSession () {
      axios({
        url: domain.testUrl + '/index/getSession',
        withCredentials: true,
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(this.getSessionRes)
    },
    PhoneLoginSucc (res) {
      console.log(res)
      this.getSession()
    }, */

    getCode() {
      axios({
        url: 'http://127.0.0.1:9003/index.php/index/setSession',
        withCredentials: true,
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(response => {
        console.log(response)
        this.uuid()
      })
    },
    uuid() {
      axios({
        url: 'http://127.0.0.1:9003/index.php/index/getSession',
        withCredentials: true,
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(response => {
        console.log(response)
      })
    },
    /*
    refreshCaptcha() {
      this.captchaUrl = `${this.captchaUrl}?${Date.now()}`; // 添加时间戳防止缓存
    }, */
    checkCaptcha() {
    axios.post('http://127.0.0.1:9001/admin/Login/aa', { captcha: this.captchaInput })
      .then(response => {
        console.log(response)
      })
      .catch(error => {
        console.error('验证失败:', error);
      })
    }
  }
}
</script>
